import requests
from lxml import etree


def totals(url='https://www.yinhuadm.xyz/v/5240.html'):
    r = requests.get(url).text
    r = etree.HTML(r)

    total = r.xpath('//div[@class="module-play-list-content module-play-list-base"]/a/@title')
    # print(len(total))
    # print(total)

    # return total
    # [
    #     {id: 1, name: "播放斗破苍穹年番第01集", url: "https://...#ep1"},
    #     {id: 2, name: "播放斗破苍穹年番第02集", url: "https://...#ep2"},
    #     ...
    # ]

    flag = {'id': '',
            'name': '',
            'url': '',
            }

    arr = []
    tem = url.split('/v/')
    s=tem[0]
    s+='/p/'
    s+=tem[1].split('.html')[0]
    s+='-1'
    for i in range(0, len(total)):
        # flag['id'] = str(i+1)
        # flag['name'] = total[i]
        arr.append(
            {'id': str(i+1),
            'title': f'第{i+1}集',
            'url': f'{s}-{i+1}.html',
            })
    print(arr)
    print(url)
    return arr

# https://www.yinhuadm.xyz/p/4870-1-2.html
if __name__ == '__main__':
    totals()
